package com.work.music.dao;

import com.work.music.entity.MusicSongster;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface MusicSongsterMapper {
    @Delete({
        "delete from music_songster",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into music_songster (uid, name, ",
        "headimg, synopsis, ",
        "status, reason, ",
        "addtime, addip)",
        "values (#{uid,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
        "#{headimg,jdbcType=VARCHAR}, #{synopsis,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=INTEGER}, #{reason,jdbcType=VARCHAR}, ",
        "#{addtime,jdbcType=TIMESTAMP}, #{addip,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(MusicSongster record);

    @Select({
        "select",
        "id, uid, name, headimg, synopsis, status, reason, addtime, addip",
        "from music_songster",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="headimg", property="headimg", jdbcType=JdbcType.VARCHAR),
        @Result(column="synopsis", property="synopsis", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    MusicSongster selectByPrimaryKey(Long id);

    @Select({
        "select",
        "id, uid, name, headimg, synopsis, status, reason, addtime, addip",
        "from music_songster"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="headimg", property="headimg", jdbcType=JdbcType.VARCHAR),
        @Result(column="synopsis", property="synopsis", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    List<MusicSongster> selectAll();

    @Update({
        "update music_songster",
        "set uid = #{uid,jdbcType=BIGINT},",
          "name = #{name,jdbcType=VARCHAR},",
          "headimg = #{headimg,jdbcType=VARCHAR},",
          "synopsis = #{synopsis,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=INTEGER},",
          "reason = #{reason,jdbcType=VARCHAR},",
          "addtime = #{addtime,jdbcType=TIMESTAMP},",
          "addip = #{addip,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(MusicSongster record);

    /**
     * 根据用户id获取歌手列表信息
     * 将歌手列表过滤去掉，默认展示所有已通过审核的歌手列表
     * 2020.05.04 LZH
     * @return
     */
    @Select({
            "select",
            "id, uid, name, headimg, synopsis, status, reason, addtime, addip, reason",
            "from music_songster",
            "where",
            "status = 1", // uid=#{uid,jdbcType=BIGINT} ${msg}
            "order by id"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="headimg", property="headimg", jdbcType=JdbcType.VARCHAR),
            @Result(column="synopsis", property="synopsis", jdbcType=JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
            @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR)
    })
    List<MusicSongster> selectListByUid(); // @Param("uid") long uid, @Param("msg") String msg
}